package game_objects;

import processing.core.PApplet;
import processing.core.PImage;


public class Shark extends Rectangle{
	
	//Instance Variables
	private PImage image;
	private PApplet parent;
	private final static int SHARK_WIDTH=120;
	private final static int SHARK_HEIGHT=40;
	private float initialspeed =  5;
	private float initialspeed2 = 10;
	private float initialspeed3 = 1;
	private int savedTime;
	private int totalTime = 5000;
	private float randomY;
	
	private float sharkX1, sharkY1, sharkWidth, sharkHeight, sharkX2,sharkY2;
	
	public Shark(PApplet p, float x, float y, int width, int height, PImage i) 
	{
		super(p, x, y, width, height);
		parent = p;
		image = i;
		sharkX1 = this.getX();
		sharkY1 = this.getY();
		sharkWidth = this.getWidth();
		sharkHeight = this.getHeight();
		sharkX2 = sharkX1+sharkWidth;
		sharkY2 = sharkY1+sharkHeight;
	}

	@Override
	public void draw(boolean drawRect) 
	{
		super.draw(false);
		if (drawRect)
		{
			parent.image(image, getX(), getY());
		}
	}
	
	public void moveLeft()
	{
		
			x-=initialspeed;
			sharkX1-=initialspeed;
			sharkX2-=initialspeed;
			int passedTime = parent.millis() - savedTime;
			   //Has five seconds passed?
			  if (passedTime > totalTime) {
			   // System.out.println( " 5 seconds have passed! " );
			    if (initialspeed<40){
					initialspeed= initialspeed + 2;
					//System.out.println(initialspeed);
		    savedTime = parent.millis(); 
			  }
			
		
			}
	}
	
	public void moveLeftShark2()
	{
		
			x-=initialspeed2;
			sharkX1-=initialspeed2;
			sharkX2-=initialspeed2;
			int passedTime = parent.millis() - savedTime;
			   //Has five seconds passed?
			  if (passedTime > totalTime) {
			   // System.out.println( " 5 seconds have passed! " );
			    if (initialspeed2<70){
					initialspeed2= initialspeed2 + 1;
					//System.out.println(initialspeed2);
		    savedTime = parent.millis(); 
			  }
			
		
			}
	}
	public void moveLeftShark3()
	{
		
			x-=initialspeed3;
			sharkX1-=initialspeed3;
			sharkX2-=initialspeed3;
			int passedTime = parent.millis() - savedTime;
			   //Has five seconds passed?
			  if (passedTime > totalTime) {
			   // System.out.println( " 5 seconds have passed! " );
			    if (initialspeed3<10){
					initialspeed3= initialspeed3 + 3;
					//System.out.println(initialspeed3);
		    savedTime = parent.millis(); 
			  }
			
		
			}
	}
	public void moveToLastXPosition(float lastXPosition)
	{
		//modify y too
		//if (x <= image.width*-1)
		if (x <= -720)
		{
			//x = lastXPosition;
			x = 720;
			randomY = parent.random(200,320);
			this.setY(randomY);
			sharkY1=this.getY();
			sharkY2 = this.getY()+sharkHeight;
			sharkX1 =this.getX();
			sharkX2 =sharkX1+sharkWidth;
		}
	}
	public void moveToLastXPositionMod(float lastXPosition)
	{
		//modify y too
		//if (x <= image.width*-1)
		if (x <= -1440)
		{
			//x = lastXPosition;
			x = 1440;
			randomY = parent.random(250,350);
			this.setY(randomY);
			sharkY1=this.getY();
			sharkY2 = this.getY()+sharkHeight;
			sharkX1 =this.getX();
			sharkX2 =sharkX1+sharkWidth;
		}
	}
	
	
	public static int getSharkWidth() 
	{
		return SHARK_WIDTH;
	}

	public static int getSharkHeight() 
	{
		return SHARK_HEIGHT;
	}

	public float getSharkX1() 
	{
		return sharkX1;
	}

	public void setSharkX1(float sharkX1) 
	{
		this.sharkX1 = sharkX1;
	}

	public float getSharkY1() 
	{
		return sharkY1;
	}

	public void setSharkY1(float sharkY1) 
	{
		this.sharkY1 = sharkY1;
	}

	public float getSharkX2() 
	{
		return sharkX2;
	}

	public void setSharkX2(float sharkX2) 
	{
		this.sharkX2 = sharkX2;
	}

	public float getSharkY2() 
	{
		return sharkY2;
	}

	public void setSharkY2(float sharkY2) 
	{
		this.sharkY2 = sharkY2;
	}

	public void setSharkWidth(float sharkWidth) 
	{
		this.sharkWidth = sharkWidth;
	}

	public void setSharkHeight(float sharkHeight) 
	{
		this.sharkHeight = sharkHeight;
	}
	
	


}
